#![allow(dead_code)]

use crate::entity::{prelude::StockInfo, stock_info};
use sea_orm::{prelude::*, sea_query::Cond, *};

pub async fn update_stock_info(db: &DbConn, models: Vec<stock_info::Model>) {
    for item in models.into_iter() {
        let query_item = item.clone();
        let cond = Cond::all().add(stock_info::Column::Code.eq(query_item.code));
        let Ok(entity) = StockInfo::find().filter(cond).one(db).await else { continue; };
        match entity {
            Some(model) => {
                let mut activemodel = model.into_active_model();
                activemodel.price = Set(item.price);
                _ = activemodel.update(db).await;
            }
            None => {
                _ = item.clone().into_active_model().insert(db).await;
            }
        }
    }
}
